package com.hehua.SingletonTwo;

public class Client {
    public static void main(String[] args) {
        //创建4个LoadBalancer对象
        LoaderBalancer balancer,balancer2,balancer3,balancer4;
        balancer = LoaderBalancer.getLoaderBalancer();
        balancer2 = LoaderBalancer.getLoaderBalancer();
        balancer3 = LoaderBalancer.getLoaderBalancer();
        balancer4 = LoaderBalancer.getLoaderBalancer();
        //判断服务器负载均衡器是否相同
        if (balancer == balancer2 && balancer2 == balancer3 && balancer3 == balancer4){
            System.out.println("服务器负载均衡器具有唯一性");
        }
        //增加服务器
        balancer.addServer("Server1");
        balancer.addServer("Server2");
        balancer.addServer("Server3");
        balancer.addServer("Server4");

        //模拟客户端请求的分发,如果输出结果为同一个server,可以将i适当放大
        //例如改为"i < 100"
        for (int i = 0; i < 10; i++) {
            String server = balancer.getServer();
            System.out.println("分发请求至服务器"+server);
        }
    }
}
